﻿package mortal.game.view.guild.redPack
{
    import extend.language.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class RedPackGuildIcon extends ActionBaseIcon
    {
        private static var _instance:RedPackGuildIcon;

        public function RedPackGuildIcon()
        {
            super(ResFileConst.RedPacketIcon);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.isShowEffect();
            return;
        }// end function

        private function isShowEffect(param1:Object = null) : void
        {
            if (Cache.instance.redPackCache.getRedPackMoney() > 0)
            {
                this.playEffect();
            }
            else
            {
                this.stopEffect();
            }
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            if (!Cache.instance.guild.hasGuild)
            {
                return MsgManager.showRollTipsMsg(Language.getString(21509), MsgRollTipsType.msgRollTips3);
            }
            Cache.instance.redPackCache.redPackState = RedPackStateType.CanGive;
            if (!RedPacketWin.isViewShow)
            {
                if (Cache.instance.redPackCache.guildRedEnvelopeInfo)
                {
                    GameProxy.guild.getRedEnvelopeInfo(Cache.instance.redPackCache.guildRedEnvelopeInfo.redId);
                }
                else
                {
                    RedPacketWin.instance.show();
                    RedPacketWin.instance.updateType();
                }
            }
            else
            {
                RedPacketWin.instance.hide();
            }
            return;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

        public static function get instance() : RedPackGuildIcon
        {
            if (!_instance)
            {
                _instance = new RedPackGuildIcon;
            }
            return _instance;
        }// end function

    }
}
